// subPages/shopPage/details/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
      currentTab:0,
      navList:[
          {
              nav:"详情"
          },{
                nav:"参数"
          }
      ],
      goodsInfo:{
          id:2,
          price:244,
          imgUrls: [
              "https://s2.ax1x.com/2019/01/11/FXumwR.jpg",
              "https://s2.ax1x.com/2019/01/11/FXuem9.jpg",
              "https://s2.ax1x.com/2019/01/11/FXuVOJ.jpg"
          ],
          title:"美膳美滋 强化营养谷物膳食 美膳美滋 强化营养谷物膳食 美膳美滋 强化营养谷物膳食美膳美滋 强化营养谷物膳食美膳美滋 强化营养谷物膳食",
          sales:255,
          detailsImg:[
              "https://jkfx.tianjinliwu.com.cn/Uploads/2019-01-11/one.jpg",
              "https://jkfx.tianjinliwu.com.cn/Uploads/2019-01-11/two.jpg"
          ],
          canshu:[
              {key:"生产许可证编号",val:"SC130DSAD122323"},
              {key:"厂址",val:"天津空港经济区六纬道60号"},
              {key:"食物材料",val:"乱七八糟 乱七八糟乱七八糟乱七八糟乱七八糟乱七八糟乱七八糟乱七八糟乱七八糟乱七八糟乱七八糟"},
              {key:"厂址",val:"天津空港经济区六纬道60号"},
              {key:"厂址",val:"天津空港经济区六纬道60号"},
              {key:"厂址",val:"天津空港经济区六纬道60号"}
          ]

      },
      indicatorDots: true,
      vertical: false,
      autoplay: true,
      circular: true,
      interval: 4000,
      duration: 500,
      previousMargin: 0,
      nextMargin: 0,
      indicatorColor:"raba(255,255,255,.3)",
      indicatorActiveColor:"#ffffff",
      imgWidth:wx.getSystemInfoSync().windowWidth
  },
    //选择导航栏
    switchNav(event){
        var cur = event.currentTarget.dataset.current;
        if (this.data.currentTab == cur) {
            return false;
        } else {
            this.setData({
                currentTab: cur
            })
        }
        this.getDetailsH()
    },
    switchTab(event){
        var cur = event.detail.current;
        this.setData({
            currentTab: cur
        });
        this.getDetailsH()
    },
    //获取swiper 图片高度
  imgHeight:function(e){
        var winW = wx.getSystemInfoSync().windowWidth;
        var imgW = e.detail.width;
        var imgH = e.detail.height;
        var swiperH = winW*imgH/imgW+"px";
        console.log(swiperH,winW,imgH,imgW);
        this.setData({
            Height:swiperH
        })
    },
    //详情是swiper高度
    getDetailsH:function(){
      let that = this;
      let winW = wx.getSystemInfoSync().windowWidth;
        console.log(winW);
        let curr=0,imgW,imgH;
      if(that.data.currentTab==0){
          let imgs = that.data.goodsInfo.detailsImg;
          for(let i=0;i<imgs.length;i++){
              wx.getImageInfo({
                src:imgs[i],
                success:function(res){
                   imgW = res.width;
                   imgH = res.height;
                   curr += imgH/(imgW/winW);
                    console.log(curr);
                    that.setData({
                        Sheight:curr
                    })
                }
              })
          }

      }
      if(that.data.currentTab==1){
          console.log(1);
          wx.createSelectorQuery().select('.canshu').boundingClientRect(function(res){
              console.log(res);
              curr = res.height;
              that.setData({
                  Sheight:curr
              })
          }).exec();
      }

    },
    //分享页面事件 内容设置
  onShareAppMessage:function(res){
     console.log(res);
     return{
         title:this.data.goodsInfo.title,
         path:"/subPages/shopPage/details/index?id="+this.data.goodsInfo.id,
         imageUrl:this.data.goodsInfo.imgUrls[0],
         success:function(res){
             wx.showToast({
                 title: '分享成功',
                 duration:2000
              })
          },
          fail:function(res){

          }
        }
  },
    checkImg:function(e){
      let cur = e.target.dataset.src;
      wx.previewImage({
          current:cur,
          urls:this.data.goodsInfo.imgUrls
      })
    },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
      console.log(options);
      this.getDetailsH();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  }
})